﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using System.Xml.Linq;
//using System.Net.Http;
using Windows.ApplicationModel;

namespace FindAnything.OpenAPI
{
    class XmlParsing
    {
        public List<Item> all_Item(String line,String sdate,String edate, String cate)
        {
            List<Item> result = new List<Item>();

            StringBuilder URL = new StringBuilder("http://cuvic.iptime.org:8080/Hackerton/*.do?command=getInfo"
                +"&position="+line+"&startDate="+sdate+"&endDate="+edate+"&cate="+cate);

            XDocument loadList = XDocument.Load(@URL.ToString());
            XElement noneCheck = loadList.Element("RESULT");
            
            
            var list = from query in loadList.Descendants("row")
                       select new Item
                       {
                           NAME = (String)query.Element("GET_NAME"),
                           GET_DATE = (String)query.Element("GET_DATE"),
                           TAKE_PLACE = (String)query.Element("TAKE_PLACE"),
                           CONTACT =  (String)query.Element("CONTACT"),
                           CATE = (String)query.Element("CATE"),
                           GET_POS = (String)query.Element("GET_POSITION"),
                           GET_PLACE = (String)query.Element("GET_PLACE"),
            
                           GET_THING = (String)query.Element("GET_THING"),
                           STATUS = (String)query.Element("STATUS"),
                           IMG_URL = (String)query.Element("IMAGE_URL")
                       };

            foreach (Item data in list)
            {
                result.Add(data);
            }

            return result;
        }
    }
}
